const mysqlUtil = require('../util/mysqlUtil');
const superagent = require('superagent');

/**
 * 定时通知测试人员验证测试包
 */
module.exports = function() {
    setInterval(function() {
        var date = new Date();
        //if (date.getHours() > 19 || date.getHours() < 8) {
        //    return;
        //}
        if (date.getHours() === 10 || date.getHours() === 15) {
            return;
        }

        var sql = "select count(1) c from t_ug_simple_package where test_status=0 and is_publish=0";
        mysqlUtil.exec(sql, [], function(err, result) {
            var c = result[0].c;

            if (c > 0) {
                var content = '@15240249259 @15195882308 当前有' + c + '个升级包还未测试，请及时测试验证，谢谢！';
                console.log(content);
                superagent.post('https://oapi.dingtalk.com/robot/send?access_token=207bb34283a65d0a5802516e2d698e3c6ea6912add990f40f1bc237522d5121c').send({
                    "msgtype": "text",
                    "text": {
                        "content": content
                    },
                    "at": {
                        "atMobiles": [
                            "15240249259", "15195882308"
                        ],
                        "isAtAll": false
                    }
                }).end(function(err, res) {
                    console.log('testNotice');
                });
            }
        });
    }, 1000 * 60 * 40);
}